var _selectedItem;
var _onSelectFunc;
var _noItemsMessage;

function On( e )
{
	GetSrc( e );
	
	if( e != _selectedItem )
	{
		e.runtimeStyle.backgroundColor = "#ADC3E7";
	}
}

function Off( e )
{
	GetSrc( e );
	
	if( e != _selectedItem )
	{
		e.runtimeStyle.backgroundColor = "";
	}
}

function SelectItem( e )
{
	GetSrc( e );

	if( e != _selectedItem )
	{
		e.runtimeStyle.backgroundColor = "#CAD3E4";
		if( _selectedItem ) _selectedItem.runtimeStyle.backgroundColor = "";
		_selectedItem = e;

		// run additional context specific code
		//
		if (_onSelectFunc)
		{
			eval( _onSelectFunc );
		}
	}
}

function GetSrc( e )
{
	if( e.tagName != "TD" )
	{
		e = e.parentElement;
	}
}

function window.onload()
{
	if(tblItems.rows.length > 0)
	{
		// select the first item
		//
		SelectItem( tblItems.rows[0].cells[0] );

		// set focus on the OK button
		//
		butBegin.focus();
	}
	else
	{
		// disable OK button if list is empty
		//
		butBegin.disabled = true;

		// display no items message
		//
		tblItems.outerHTML = "<table style='width:100%; height:100%;'><tr><td style='height:100%;text-align:center;color:#999999;'>" + _noItemsMessage + "<br><br></td></tr></table>";
	}
}

function document.onkeydown()
{
	try
	{
		switch (event.keyCode)
		{
			case 116: // F5
				event.keyCode =0;
				event.returnValue = false;
				
			case 38: // up
				if (_selectedItem.parentElement.previousSibling.children[0].item != undefined)
				{
					SelectItem(_selectedItem.parentElement.previousSibling.children[0]);
				}
				break;

			case 40: // down
				if (_selectedItem.parentElement.nextSibling.children[0].item != undefined)
				{
					SelectItem(_selectedItem.parentElement.nextSibling.children[0]);
				}
				break;
		}
	}
	catch(e)
	{
	}
}

